package src

import java.util.List
import model.Partida
import model.Villano
import org.apache.wicket.markup.html.basic.Label
import org.apache.wicket.model.PropertyModel
import org.uqbar.wicket.xtend.WicketExtensionFactoryMethods
import org.uqbar.wicket.xtend.XLink
import org.uqbar.wicket.xtend.XListView

class ExpedientesPage extends VistaElementos<Villano> {
		
		extension WicketExtensionFactoryMethods = new WicketExtensionFactoryMethods
	
	
	new (Partida partida) {
		super(partida)
		this.addChild(new XLink("mapamundi") => [onClick = [| responsePage = new MapaMundiPage(partida) ] ] )
		this.addChild(listViewGenerator(partida.bddVillano.villanos))
		this.addChild(new XLink("nuevo") => [onClick = [| responsePage = new EdicionVillano(partida, new Villano)]])
	}
	
	override listViewGenerator(List<Villano> elementos) {
			var listview = new XListView("informacion", elementos)
		listview.populateItem = [item | 
			item.addChild(new Label("nombre", new PropertyModel(item.modelObject, "nombre" )))
			item.addChild(new XLink("editar") => [ onClick = [| responsePage = new EdicionVillano(partida, item.modelObject)  ] ] )
			item.addChild(new XLink("eliminar") => [ onClick = [| elementos.remove(item.modelObject)] ] )
		]
			listview
	}
	
	
	
	
	

}